package ex_from_web;


/**
 * Differce between 
 * Java Abstract class and Java Interface example 
 */
interface PenInterface {
    /* Can contain constants and method declarations */
    final String defaultColor = "black";
    public void showColor();
    public void draw();
}

abstract class PenAbstract {
    /* Abstract class contain variables, constants,
     * implemented and declared (abstract) methods */
    final String defaultColor = "black";
    String color;
    
    PenAbstract(String color) {
        this.color = color;
    }
    /* Implementation is in subclasses */
    abstract public void draw();
            
    /* Default behavior which will inherit all subclasses.
     * Subclasses can change it */
    public void showColor() {
        if (color.trim().isEmpty()) {
            color = defaultColor;
            System.out.println("Color field is empty! Default color is " 
                    + defaultColor);
        } else {
            System.out.println("Pen color is " + color);
        }
    }
}

class PenI implements PenInterface {
    String color;
    
    PenI(String color) {
        this.color = color;
    }
    
    public void draw() {
        System.out.println("Drawing with " + color + " color");
    }
    
    /* If you want default behavior, you have to
     * implement it in all classes which
     * implement an Interface
     */
    
    public void showColor() {
        if (color.trim().isEmpty()) {
            color = defaultColor;
            System.out.println("Color field is empty! Default color is " 
                    + defaultColor);
        } else {
            System.out.println("Pen color is " + color);
        }
    }
    
}

class PenA extends PenAbstract {

    PenA(String color) {
        super(color);
    }

    public void draw() {
        System.out.println("Drawing with " + color + " color");
    }
}

public class interface_abstract_example {
  public static void main(String[] args) {
        PenI penI1 = new PenI("red");
        PenI penI2 = new PenI("");
        PenA penA1 = new PenA("blue");
        PenA penA2 = new PenA("");
        
        penI1.draw();
        penI1.showColor();
        penI2.showColor(); 
        penA1.draw();
        penA1.showColor();
        penA2.showColor(); 
    }

}